package locations.actions;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import locations.dao.implement.InstitutionDAOHibernateJPA;
import locations.dao.implement.PacientDAOHibernateJPA;
import locations.dao.implement.PracticeTypeDAOHibernateJPA;
import locations.dao.implement.ProblematicTypeDAOHibernateJPA;
import locations.dao.implement.ProfesionalDAOHibernateJPA;
import locations.model.Institution;
import locations.model.InstitutionResponsible;
import locations.model.InstitutionType;
import locations.model.Location;
import locations.model.Pacient;
import locations.model.Profesional;
import locations.model.TipoPractica;
import locations.model.TipoProblematica;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;

import com.opensymphony.xwork2.ActionSupport;
import locations.dao.implement.UserDAOHibernateJPA;
import locations.model.Usuario;

public class CargarBaseAction extends ActionSupport 
        implements ServletRequestAware, ServletResponseAware
{

    private static final long serialVersionUID = -8124967730231198191L;
	
    private HttpServletRequest request; 
    private HttpServletResponse response; 

    public String execute()
    {
//        dao.save(this.speciality);
        PacientDAOHibernateJPA pacientDAOHibernateJPA = new PacientDAOHibernateJPA();
        
        if (pacientDAOHibernateJPA.retrieveAll().isEmpty())
        {
            Pacient pacient1 = new Pacient();
            pacient1.setNombre("Ramon");
            pacient1.setApellido("Perez");
            pacient1.setDocumento("4.237.214");
            pacient1.setSexo("M");
            pacient1.setFechaNacimiento(new Date(1990,06,06));
            pacient1.setCondicionesHabitacionales("Buena");
            Location location1 = new Location();
            location1.setProvince("Buenos Aires");
            location1.setCity("La Plata");
            location1.setDistrict("Algo");
            location1.setLatitude(-34.94746934566666);
            location1.setLongitude(-57.95413613319397);
            location1.setNumber("343");
            location1.setStreet("43");
            pacient1.setLocation(location1);
            pacientDAOHibernateJPA.save(pacient1);
            Pacient pacient2 = new Pacient();
            pacient2.setNombre("Laura");
            pacient2.setApellido("Panzi");
            pacient2.setDocumento("3.212.263");
            pacient2.setSexo("F");
            pacient2.setFechaNacimiento(new Date(1957,12,14));
            pacient2.setCondicionesHabitacionales("Buena");
            Location location2 = new Location();
            location2.setProvince("Buenos Aires");
            location2.setCity("La Plata");
            location2.setDistrict("Algo");
            location2.setLatitude(-34.94746934566646);
            location2.setLongitude(-57.95413613319497);
            location2.setNumber("1211");
            location2.setStreet("33");
            pacient2.setLocation(location2);
            pacientDAOHibernateJPA.save(pacient2);
            Pacient pacient3 = new Pacient();
            pacient3.setNombre("Santina");
            pacient3.setApellido("Larz");
            pacient3.setDocumento("38.212.263");
            pacient3.setSexo("F");
            pacient3.setFechaNacimiento(new Date(2000,7,4));
            pacient3.setCondicionesHabitacionales("Mala");
            Location location3 = new Location();
            location3.setProvince("Buenos Aires");
            location3.setCity("La Plata");
            location3.setDistrict("Algo");
            location3.setLatitude(-34.94746934566636);
            location3.setLongitude(-57.95413613319437);
            location3.setNumber("1221");
            location3.setStreet("73");
            pacient3.setLocation(location3);
            pacientDAOHibernateJPA.save(pacient3);

            Profesional profesional1 = new Profesional("Lautaro", "Moneti", "123123", "Pediatria", "Niños");
            profesional1.setSexo("M");
            Profesional profesional2 = new Profesional("Mariel", "Rapo", "112223", "Psicologia", "Adolescentes");
            profesional2.setSexo("F");
            Profesional profesional3 = new Profesional("Marcelo", "Bajac", "54544", "Odontologia", "Adultos");
            profesional3.setSexo("M");

            ProfesionalDAOHibernateJPA profesionalDAOHibernateJPA = new ProfesionalDAOHibernateJPA();
            profesionalDAOHibernateJPA.save(profesional1);
            profesionalDAOHibernateJPA.save(profesional2);
            profesionalDAOHibernateJPA.save(profesional3);

            Institution institution1 = new Institution();
            institution1.setName("Hospital de niños");
            institution1.setEmail("hospital@hospital.com");
            institution1.setPhoneNumbers("4293279 15-233-4268");
            institution1.setDetail("Hospital especializado en enfermedades hereditarias (?)");
            Location location4 = new Location();
            location4.setProvince("Buenos Aires");
            location4.setCity("La Plata");
            location4.setDistrict("Algo");
            location4.setLatitude(-34.91158121548803);
            location4.setLongitude(-57.94658303260803);
            location4.setNumber("134");
            location4.setStreet("23");
            institution1.setLocation(location4);
            InstitutionType institutionType1 = new InstitutionType("Tipo 1");
            institution1.setType(institutionType1);
            InstitutionResponsible institutionResponsible1 = new InstitutionResponsible("Mario", "Mana", "mmana@mail.com", "155555555", "Doctor");
            institution1.setResponsible(institutionResponsible1);
            InstitutionDAOHibernateJPA institutionDAOHibernateJPA = new InstitutionDAOHibernateJPA();
            institutionDAOHibernateJPA.save(institution1);

            TipoPractica tipoPractica1 = new TipoPractica("02", "Interconsulta", "30 minutos", "Prestacion social cuyo....");
            TipoPractica tipoPractica2 = new TipoPractica("03", "Prestacion social minima", "10 minutos", "Incluye las actividades...");
            TipoPractica tipoPractica3 = new TipoPractica("04", "Prestacion social intermedia", "25 minutos", "Encuesta social unica, ...");
            PracticeTypeDAOHibernateJPA practiceTypeDAOHibernateJPA = new PracticeTypeDAOHibernateJPA();
            practiceTypeDAOHibernateJPA.save(tipoPractica1);
            practiceTypeDAOHibernateJPA.save(tipoPractica2);
            practiceTypeDAOHibernateJPA.save(tipoPractica3);

            TipoProblematica tipoProblematica1 = new TipoProblematica("Violencia familiar", "....");
            TipoProblematica tipoProblematica2 = new TipoProblematica("Tipo problematica 2", "otro tipo");
            ProblematicTypeDAOHibernateJPA problematicTypeDAOHibernateJPA = new ProblematicTypeDAOHibernateJPA();
            problematicTypeDAOHibernateJPA.save(tipoProblematica1);
            problematicTypeDAOHibernateJPA.save(tipoProblematica2);

            UserDAOHibernateJPA userDAOHibernateJPA = new UserDAOHibernateJPA();
            Usuario u = new Usuario();
            u.setUsuario("admin");
            u.setContrasena("admin");
            u.setRol("Administrador");
            userDAOHibernateJPA.save(u);
        }
        
        return SUCCESS;
    }

    public HttpServletRequest getRequest()
    {
        return request;
    }

    public void setRequest(HttpServletRequest request)
    {
        this.request = request;
    }

    public void setResponse(HttpServletResponse response)
    {
        this.response = response;
    }

    public HttpServletResponse getResponse()
    {
        return this.response;
    }

    @Override
    public void setServletResponse(HttpServletResponse response)
    {
        this.response = response;
    }

    @Override
    public void setServletRequest(HttpServletRequest request)
    {
        this.request = request;
    }
    
}
